//
//  XS_ZhaopinVC.swift
//  XueDao
//
//  Created by 韩云智 on 2020/12/6.
//

import UIKit
import RxSwift
import RxCocoa
import RxDataSources
import MJRxSwift

class XS_queryRecruitmentListM: XS_BaseModel {
    var id = 0 // 招聘信息编号
    var positionName = "" // 招聘名称
    var experienceRequirement = "" // 经验要求
    var minDegree = "" // 最低学历
    var salaryRange = "" // 薪水范围
    var workPlace = "" // 工作地点
    var detailAddress = "" // 详细地址
    var companyName = "" // 公司名称
    var companyLogoUrl = "" // 公司logo图片地址
    var industryName = "" // 行业名
    var industryId = 0 // 行业编号
    var positionDescription = "" // 岗位描述
    var workWay = "" // 工作方式
}
class XS_queryRecruitmentM: XS_BaseModel {
    var records: [XS_queryRecruitmentListM] = []
    var total = 0 // 总记录数
    var size = 0 // 每页数据量
    var current = 0 // 当前页码
    var searchCount = false // 无需渲染
    var pages = 0 // 总页数
}

class XS_queryDictionaryM: XS_BaseModel {
    var salaryList: [String] = [] // 薪资范围数据集合
    var experienceList: [String] = [] // 经验要求数据集合
}

class XS_ZhaopinVC: XS_BaseVC {
    
    lazy var table = UITableView(frame: .zero, style: .grouped)
    lazy var tapPS = PublishSubject<Int>()
    lazy var text1 = "综合排序"
    lazy var btn1PS = PublishSubject<String>()
    lazy var text2: [XS_HomeTopM] = []
    lazy var btn2PS = PublishSubject<[XS_HomeTopM]>()
    lazy var text3: [String] = ["不限", "不限"]
    lazy var btn3PS = PublishSubject<[String]>()
    lazy var page = 0
    lazy var searchText = ""
    private lazy var dataPS = PublishSubject<[XS_queryRecruitmentListM]>()
    private lazy var data: [XS_queryRecruitmentListM] = []
    private lazy var footer = MJRefreshBackNormalFooter()
    
    override func upConfig() {
        shouldNavBarHidden = true
    }
    override func upView() {
        loadCustomBar()
        
        let search = QMUITextField(frame: CGRect(x: .scale*56, y: .barHeight + (44 - .scale*32)/2, width: .scale*304, height: .scale*32))
        search.placeholder = "请搜索公司名称/岗位"
        let leftView = UIView(frame: CGRect(x: 0, y: 0, width: .scale*32, height: .scale*32))
        let searchImgV = UIImageView(image: UIImage(named: "icon_16px_搜索备份"))
        searchImgV.frame = CGRect(x: 8, y: 8, width: 16, height: 16) * .scale
        leftView.addSubview(searchImgV)
        search.leftView = leftView
        search.leftViewMode = .always
        search.placeholderColor = #colorLiteral(red: 0.768627451, green: 0.7764705882, blue: 0.8039215686, alpha: 1)
        search.font = .xsFont(name: .regular, .scale*12)
        search.layer.cornerRadius = .scale*16
        search.layer.backgroundColor = #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1)
        search.returnKeyType = .search
        view.addSubview(search)
        
        search.rx.controlEvent(.editingDidEndOnExit)
            .subscribe(onNext: { [weak self] in
                self?.searchText = search.text ?? ""
                self?.page = 0
                self?.loadMore()
            }).disposed(by: disposeBag)
        
        do {
            let btn = getBtn("综合排序")
            view.addSubview(btn)
            btn.snp.makeConstraints {
                $0.width.equalTo(.scale*88)
                $0.height.equalTo(.scale*44)
                $0.top.equalTo(customBar.snp.bottom)
                $0.left.equalToSuperview()
            }
            let imgV = UIImageView(image: UIImage(named: "icon_12px_更多_2"))
            imgV.frame = CGRect(x: .scale*76, y: .scale*16, width: .scale*12, height: .scale*12)
            btn.addSubview(imgV)
            
            let maskView = UIView()
            maskView.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4)
            maskView.isHidden = true
            view.addSubview(maskView)
            maskView.snp.makeConstraints {
                $0.top.equalTo(customBar.snp.bottom).offset(.scale*44)
                $0.left.bottom.right.equalToSuperview()
            }
            let shapeLayer = CAShapeLayer()
            shapeLayer.fillColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
            maskView.layer.addSublayer(shapeLayer)
            let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: .screenWidth, height: .scale*64), byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: .scale*8, height: .scale*8))
            shapeLayer.path = path.cgPath
            
//            let arr = ["综合排序", "附近", "最新"]
            let arr = ["综合排序", "最新"]
            for (index, text) in arr.enumerated() {
                let button = getBtn(text)
                button.layer.cornerRadius = .scale*16
                button.frame = CGRect(x: 16 + index * (80 + 52), y: 16, width: 80, height: 32) * .scale
                maskView.addSubview(button)
                button.rx.tap.asDriver()
                    .drive(onNext: { [weak self] in
                        self?.text1 = text
                        self?.btn1PS.onNext(text)
                        self?.tapPS.onNext(0)
                    }).disposed(by: disposeBag)
                btn1PS.subscribe(onNext: { str in
                    btn.setTitle(str, for: .normal)
                    if str == text {
                        button.isSelected = true
                        button.layer.backgroundColor = #colorLiteral(red: 0.1647058824, green: 0.7411764706, blue: 0.6117647059, alpha: 0.1)
                    } else {
                        button.isSelected = false
                        button.layer.backgroundColor = nil
                    }
                }).disposed(by: disposeBag)
            }
            btn1PS.onNext(text1)
            
            let tag = 1
            btn.rx.tap.asDriver()
                .map({ btn.isSelected ? 0 : tag })
                .drive(tapPS)
                .disposed(by: disposeBag)
            tapPS.asDriver(onErrorJustReturn: 0)
                .drive(onNext: { [weak self] type in
                    btn.isSelected = type == tag
                    imgV.image = UIImage(named: type == tag ? "icon_12px_更多_1" : "icon_12px_更多_2")
                    maskView.isHidden = type != tag
                    self?.view.bringSubviewToFront(maskView)
                    if type == 0 {
                        self?.page = 0
                        self?.loadMore()
                    }
                }).disposed(by: disposeBag)
        }
        
        let allIndustryApi = XS_Singleton.shared.infoModel == nil ? "/industry/queryAllIndustryApi" : "/industry/queryAllStatusApi"
        XS_NetWork.requestJson(allIndustryApi)
            .mapModels(type: XS_HomeTopM.self)
            .subscribe(onNext: { [weak self] models, resp in
                guard let `self` = self, resp.success else { return }
                
                let btn = self.getBtn("行业领域")
                self.view.addSubview(btn)
                btn.snp.makeConstraints {
                    $0.width.equalTo(.scale*88)
                    $0.height.equalTo(.scale*44)
                    $0.top.equalTo(self.customBar.snp.bottom)
                    $0.centerX.equalToSuperview().offset(-.scale*16)
                }
                let imgV = UIImageView(image: UIImage(named: "icon_12px_更多_2"))
                imgV.frame = CGRect(x: .scale*76, y: .scale*16, width: .scale*12, height: .scale*12)
                btn.addSubview(imgV)
                
                let maskView = UIView()
                maskView.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4)
                maskView.isHidden = true
                self.view.addSubview(maskView)
                maskView.snp.makeConstraints {
                    $0.top.equalTo(self.customBar.snp.bottom).offset(.scale*44)
                    $0.left.bottom.right.equalToSuperview()
                }
                let shapeLayer = CAShapeLayer()
                shapeLayer.fillColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
                maskView.layer.addSublayer(shapeLayer)
                let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: .screenWidth, height: .scale*288), byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: .scale*8, height: .scale*8))
                shapeLayer.path = path.cgPath
                
//                let arr = ["会计财务", "母婴护理", "行业领域", "行业领域1", "行业领域2", "行业领域3", "行业领域4", "行业领域5", "行业领域6", "行业领域7"]
                for (index, item) in models.enumerated() {
                    let button = self.getBtn(XS_Singleton.shared.infoModel == nil ? item.name : item.industryName)
                    button.layer.cornerRadius = .scale*16
                    button.frame = CGRect(x: 16 + index%3*(104+16), y: 16 + index/3*(32+16), width: 104, height: 32) * .scale
                    maskView.addSubview(button)
                    button.rx.tap.asDriver()
                        .drive(onNext: { [weak self] in
                            guard let `self` = self else { return }
                            if self.text2.contains(where: { $0.id == item.id}) {
                                self.text2.removeAll { $0.id == item.id }
                            } else {
                                self.text2.append(item)
                            }
                            self.btn2PS.onNext(self.text2)
                        }).disposed(by: self.disposeBag)
                    self.btn2PS.subscribe(onNext: { models in
                        if models.contains(where: { $0.id == item.id}) {
                            button.isSelected = true
                            button.layer.backgroundColor = #colorLiteral(red: 0.1647058824, green: 0.7411764706, blue: 0.6117647059, alpha: 0.1)
                        } else {
                            button.isSelected = false
                            button.layer.backgroundColor = #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1)
                        }
                    }).disposed(by: self.disposeBag)
                }
                self.btn2PS.onNext(self.text2)
                let clean = self.getClean()
                clean.frame = CGRect(x: 16, y: 232, width: 111, height: 40) * .scale
                maskView.addSubview(clean)
                clean.rx.tap.asDriver()
                    .drive(onNext: { [weak self] in
                        self?.text2.removeAll()
                        self?.btn2PS.onNext([])
                    }).disposed(by: self.disposeBag)
                let sure = self.getSure()
                sure.frame = CGRect(x: 143, y: 232, width: 216, height: 40) * .scale
                maskView.addSubview(sure)
                sure.rx.tap.asDriver()
                    .drive(onNext: { [weak self] in
                        self?.tapPS.onNext(0)
                    }).disposed(by: self.disposeBag)
                
                let tag = 2
                btn.rx.tap.asDriver()
                    .map({ btn.isSelected ? 0 : tag })
                    .drive(self.tapPS)
                    .disposed(by: self.disposeBag)
                self.tapPS.asDriver(onErrorJustReturn: 0)
                    .drive(onNext: { [weak self] type in
                        btn.isSelected = type == tag
                        imgV.image = UIImage(named: type == tag ? "icon_12px_更多_1" : "icon_12px_更多_2")
                        maskView.isHidden = type != tag
                        self?.view.bringSubviewToFront(maskView)
                    }).disposed(by: self.disposeBag)
                
            }).disposed(by: disposeBag)
        
        
        XS_NetWork.requestJson("/recruitment/queryDictionary")
            .mapModel(type: XS_queryDictionaryM.self)
            .subscribe(onNext: { [weak self] model, resp in
                guard let `self` = self, resp.success, let model = model else { return }
                
                let btn = self.getBtn("更多筛选")
                self.view.addSubview(btn)
                btn.snp.makeConstraints {
                    $0.width.equalTo(.scale*88)
                    $0.height.equalTo(.scale*44)
                    $0.top.equalTo(self.customBar.snp.bottom)
                    $0.right.equalToSuperview().offset(-.scale*16)
                }
                let imgV = UIImageView(image: UIImage(named: "icon_12px_删选"))
                imgV.frame = CGRect(x: .scale*76, y: .scale*16, width: .scale*12, height: .scale*12)
                btn.addSubview(imgV)
                
                let maskView = UIView()
                maskView.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.4)
                maskView.isHidden = true
                self.view.addSubview(maskView)
                maskView.snp.makeConstraints {
                    $0.top.equalTo(self.customBar.snp.bottom).offset(.scale*44)
                    $0.left.bottom.right.equalToSuperview()
                }
                let shapeLayer = CAShapeLayer()
                shapeLayer.fillColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
                maskView.layer.addSublayer(shapeLayer)
                let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: .screenWidth, height: .scale*464), byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: .scale*8, height: .scale*8))
                shapeLayer.path = path.cgPath
                
                let label1 = UILabel.xsLabel(size: .scale*14, fontName: .medium, color: #colorLiteral(red: 0.2196078431, green: 0.2352941176, blue: 0.2470588235, alpha: 1), text: "期望薪资")
                maskView.addSubview(label1)
                label1.snp.makeConstraints({
                    $0.left.top.equalTo(.scale*16)
                })
//                let arr1 = ["不限", "5K以下", "5-8K", "8-10K", "10-15K", "15-20K", "20-50K", "50K以上"]
                for (index, text) in model.salaryList.enumerated() {
                    let button = self.getBtn(text)
                    button.layer.cornerRadius = .scale*16
                    button.frame = CGRect(x: 16 + index%3*(104+16), y: 52 + index/3*(32+16), width: 104, height: 32) * .scale
                    maskView.addSubview(button)
                    button.rx.tap.asDriver()
                        .drive(onNext: { [weak self] in
                            guard let `self` = self else { return }
                            self.text3[0] = text
                            self.btn3PS.onNext(self.text3)
                        }).disposed(by: self.disposeBag)
                    self.btn3PS.subscribe(onNext: { str in
                        if str.first == text {
                            button.isSelected = true
                            button.layer.backgroundColor = #colorLiteral(red: 0.1647058824, green: 0.7411764706, blue: 0.6117647059, alpha: 0.1)
                        } else {
                            button.isSelected = false
                            button.layer.backgroundColor = #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1)
                        }
                    }).disposed(by: self.disposeBag)
                }
                let label2 = UILabel.xsLabel(size: .scale*14, fontName: .medium, color: #colorLiteral(red: 0.2196078431, green: 0.2352941176, blue: 0.2470588235, alpha: 1), text: "经验要求")
                maskView.addSubview(label2)
                label2.snp.makeConstraints({
                    $0.left.equalTo(.scale*16)
                    $0.top.equalTo(.scale*204)
                })
//                let arr2 = ["不限", "在校生", "应届生", "1年以内", "1-3年", "3-5年", "5-10年", "10年以上"]
                for (index, text) in model.experienceList.enumerated() {
                    let button = self.getBtn(text)
                    button.layer.cornerRadius = .scale*16
                    button.frame = CGRect(x: 16 + index%3*(104+16), y: 240 + index/3*(32+16), width: 104, height: 32) * .scale
                    maskView.addSubview(button)
                    button.rx.tap.asDriver()
                        .drive(onNext: { [weak self] in
                            guard let `self` = self else { return }
                            self.text3[1] = text
                            self.btn3PS.onNext(self.text3)
                        }).disposed(by: self.disposeBag)
                    self.btn3PS.subscribe(onNext: { str in
                        if str.last == text {
                            button.isSelected = true
                            button.layer.backgroundColor = #colorLiteral(red: 0.1647058824, green: 0.7411764706, blue: 0.6117647059, alpha: 0.1)
                        } else {
                            button.isSelected = false
                            button.layer.backgroundColor = #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1)
                        }
                    }).disposed(by: self.disposeBag)
                }
                self.btn3PS.onNext(self.text3)
                let clean = self.getClean()
                clean.frame = CGRect(x: 16, y: 408, width: 111, height: 40) * .scale
                maskView.addSubview(clean)
                clean.rx.tap.asDriver()
                    .drive(onNext: { [weak self] in
                        self?.text3 = ["不限", "不限"]
                        self?.btn3PS.onNext(["不限", "不限"])
                    }).disposed(by: self.disposeBag)
                let sure = self.getSure()
                sure.frame = CGRect(x: 143, y: 408, width: 216, height: 40) * .scale
                maskView.addSubview(sure)
                sure.rx.tap.asDriver()
                    .drive(onNext: { [weak self] in
                        self?.tapPS.onNext(0)
                    }).disposed(by: self.disposeBag)
                
                let tag = 3
                btn.rx.tap.asDriver()
                    .map({ btn.isSelected ? 0 : tag })
                    .drive(self.tapPS)
                    .disposed(by: self.disposeBag)
                self.tapPS.asDriver(onErrorJustReturn: 0)
                    .drive(onNext: { [weak self] type in
                        btn.isSelected = type == tag
                        imgV.image = UIImage(named: type == tag ? "icon_12px_删选" : "icon_12px_删选")
                        maskView.isHidden = type != tag
                        self?.view.bringSubviewToFront(maskView)
                    }).disposed(by: self.disposeBag)
                
            }).disposed(by: disposeBag)
        
        table.showsVerticalScrollIndicator = false
//        table.bounces = false
        table.contentInsetAdjustmentBehavior = .never
        table.separatorStyle = .none
        table.backgroundColor = #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1)
        table.rowHeight = .scale*126
        table.sectionHeaderHeight = 0
        table.sectionFooterHeight = 0
        table.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: .screenWidth, height: .scale*16))
        table.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: .screenWidth, height: 0.01))
        table.register(XS_ZhaopinCell.self, forCellReuseIdentifier: "cell")
        view.addSubview(table)
        table.snp.makeConstraints({
            $0.top.equalTo(customBar.snp.bottom).offset(.scale*44)
            $0.left.bottom.right.equalToSuperview()
        })
        table.rx.modelSelected(XS_queryRecruitmentListM.self)
            .asDriver()
            .drive(onNext: { model in
                let vc = XS_ZhaopinDetailVC()
                vc.model = model
                XS_NVC.shared.pushViewController(vc, animated: true)
            }).disposed(by: disposeBag)
        
        let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, XS_queryRecruitmentListM>>(configureCell: { ds, tv, ip, it in
            let cell = tv.dequeueReusableCell(withIdentifier: "cell", for: ip) as! XS_ZhaopinCell
            cell.modelPS.onNext(it)
            return cell
        })
        
        dataPS.asDriver(onErrorJustReturn: [])
            .flatMapLatest { Driver.just([SectionModel<String, XS_queryRecruitmentListM>(model: "", items: $0)]) }
            .drive(table.rx.items(dataSource: dataSource))
            .disposed(by: disposeBag)
        
        table.mj_footer = footer
        footer.rx.refresh
            .subscribe(onNext: { [weak self] state in
                guard let `self` = self, state == .refreshing else { return }
                self.loadMore()
            }).disposed(by: disposeBag)
        
        loadMore()
    }
    
    func loadMore() {
        if page == 0 {
            data.removeAll()
        }
        var param: [String:Any] = [
            "pageNo":page+1,
            "industryId":text2.compactMap({ $0.id }),
            "positionName":searchText,
            "experienceRequirement":text3[1],
            "salaryRange":text3[0]
        ]
        switch text1 {
        case "最新": param["sortWay"] = "new"
        case "附近": param["sortWay"] = "near"
        default: break
        }
        
        XS_NetWork.requestJson("/recruitment/queryRecruitment", parameters: param)
            .mapModel(type: XS_queryRecruitmentM.self)
            .subscribe(onNext: { [weak self] model, resp in
                guard let `self` = self, resp.success, let model = model else { return }
                self.page = model.current
                self.data += model.records
                self.dataPS.onNext(self.data)
                if model.current < model.pages {
                    self.footer.endRefreshing()
                } else {
                    self.footer.endRefreshingWithNoMoreData()
                }
            }).disposed(by: disposeBag)
    }

    private func getBtn(_ text: String) -> UIButton {
        let btn = XS_NoHighlightBtn()
        btn.setTitle(text, for: .normal)
        btn.setTitleColor(#colorLiteral(red: 0.4470588235, green: 0.4666666667, blue: 0.4862745098, alpha: 1), for: .normal)
        btn.setTitleColor(#colorLiteral(red: 0.1647058824, green: 0.7411764706, blue: 0.6117647059, alpha: 1), for: .selected)
        btn.titleLabel?.font = .xsFont(name: .regular, .scale*14)
        return btn
    }
    private func getClean() -> UIButton {
        let btn = XS_NoHighlightBtn()
        btn.layer.cornerRadius = .scale*4
        btn.layer.backgroundColor = #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1)
        btn.setTitle("清除", for: .normal)
        btn.setTitleColor(#colorLiteral(red: 0.2196078431, green: 0.2352941176, blue: 0.2470588235, alpha: 1), for: .normal)
        btn.titleLabel?.font = .xsFont(name: .medium, .scale*16)
        return btn
    }
    private func getSure() -> UIButton {
        let btn = XS_NoHighlightBtn()
        btn.layer.cornerRadius = .scale*4
        btn.layer.backgroundColor = #colorLiteral(red: 0.1647058824, green: 0.7411764706, blue: 0.6117647059, alpha: 1)
        btn.setTitle("确定", for: .normal)
        btn.setTitleColor(#colorLiteral(red: 1, green: 1, blue: 1, alpha: 1), for: .normal)
        btn.titleLabel?.font = .xsFont(name: .medium, .scale*16)
        return btn
    }
}

class XS_ZhaopinCell: XS_BaseTCell {
    lazy var modelPS = PublishSubject<XS_queryRecruitmentListM>()
    
    let 备份 = "Image may contain cartoon, illustration and screenshot备份"
    override func upView() {
        selectionStyle = .none // 去掉点击样式
        backgroundColor = UIColor.clear
        
        let bgView = UIView()
        bgView.layer.masksToBounds = true
        bgView.layer.cornerRadius = .scale * 4
        bgView.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        bgView.frame = CGRect(x: .scale*17, y: 0, width: .scale*342, height: .scale*118)
        contentView.addSubview(bgView)
        
        let salaryRangeLab = UILabel.xsLabel(size: .scale*18, fontName: .medium, color: #colorLiteral(red: 0.9294117647, green: 0.3960784314, blue: 0.2470588235, alpha: 1), alignment: .right, text: "8-12K")
        bgView.addSubview(salaryRangeLab)
        salaryRangeLab.snp.makeConstraints({
            $0.top.equalTo(.scale*16)
            $0.right.equalTo(-.scale*16)
        })
        
        let positionNameLab = UILabel.xsLabel(size: .scale*18, fontName: .medium, color: #colorLiteral(red: 0.2196078431, green: 0.2352941176, blue: 0.2470588235, alpha: 1), text: "招聘职位招聘职位招聘职位")
        bgView.addSubview(positionNameLab)
        positionNameLab.snp.makeConstraints {
            $0.left.top.equalTo(.scale*16)
            $0.right.lessThanOrEqualTo(salaryRangeLab.snp.left).offset(-.scale*8)
        }
        
        let companyNameLab = UILabel.xsLabel(size: .scale*14, fontName: .regular, color: #colorLiteral(red: 0.4470588235, green: 0.4666666667, blue: 0.4862745098, alpha: 1), text: "XXX公司")
        bgView.addSubview(companyNameLab)
        companyNameLab.snp.makeConstraints({
            $0.left.equalTo(.scale * 16)
            $0.bottom.equalTo(-.scale * 18)
        })
        let workWayLab = UILabel.xsLabel(size: .scale*16, fontName: .medium, color: UIColor(red: 0.16, green: 0.74, blue: 0.61, alpha: 1.00), alignment: .right, text: "北京市 朝阳区")
        bgView.addSubview(workWayLab)
        workWayLab.snp.makeConstraints({
            $0.right.equalTo(-.scale * 16)
            $0.centerY.equalTo(companyNameLab.snp.centerY)
        })
        
        let (v0, workPlaceLab) = getTagView()
        bgView.addSubview(v0)
        v0.snp.makeConstraints({
            $0.height.equalTo(.scale*20)
            $0.top.equalTo(.scale*46)
            $0.left.equalTo(.scale*15)
        })
        
        let (v1, experienceRequirementLab) = getTagView()
        bgView.addSubview(v1)
        v1.snp.makeConstraints({
            $0.height.equalTo(.scale*20)
            $0.top.equalTo(.scale*46)
            $0.left.equalTo(v0.snp.right).offset(.scale*8)
        })
        
        let (v2, industryNameLab) = getTagView()
        bgView.addSubview(v2)
        v2.snp.makeConstraints({
            $0.height.equalTo(.scale*20)
            $0.top.equalTo(.scale*46)
            $0.left.equalTo(v1.snp.right).offset(.scale*8)
        })
        
        modelPS.subscribe(onNext: { item in
            positionNameLab.text = item.positionName
            salaryRangeLab.text = item.salaryRange
            companyNameLab.text = item.companyName
            workWayLab.text = item.workWay
            workPlaceLab.text = item.workPlace
            experienceRequirementLab.text = item.experienceRequirement
            industryNameLab.text = item.industryName
        }).disposed(by: disposeBag)
    }
    
    func getTagView() -> (UIView, UILabel) {
        let view = UIView()
        view.layer.cornerRadius = .scale*10
        view.layer.backgroundColor = #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1)
        let label = UILabel.xsLabel(size: .scale*12, fontName: .regular, color: UIColor(red: 0.16, green: 0.74, blue: 0.61, alpha: 1.0))
        view.addSubview(label)
        label.snp.makeConstraints({
            $0.center.equalToSuperview()
            $0.left.equalTo(.scale * 6)
            $0.right.equalTo(-.scale*6)
        })
        return (view, label)
    }
}
